package cyclestats

import "time"

func timeTruncate(timeUnit time.Duration, ts time.Time) time.Time {
	switch timeUnit {
	case StatsTimeUnitSecond:
		return ts.Truncate(time.Minute)
	case StatsTimeUnitMinute:
		return ts.Truncate(time.Hour)
	case StatsTimeUnitHour:
		return ts.Truncate(time.Hour * 24)
	default:
		return ts
	}
}

func timeIndex(timeUnit time.Duration, ts time.Time) int {
	switch timeUnit {
	case StatsTimeUnitSecond:
		return ts.Second()
	case StatsTimeUnitMinute:
		return ts.Minute()
	case StatsTimeUnitHour:
		return ts.Hour()
	default:
		return 0
	}
}

func timeUnitUpper(timeUnit time.Duration) time.Duration {
	switch timeUnit {
	case StatsTimeUnitSecond:
		return StatsTimeUnitMinute
	case StatsTimeUnitMinute:
		return StatsTimeUnitHour
	case StatsTimeUnitHour:
		return StatsTimeUnitHour
	default:
		return StatsTimeUnitHour
	}
}
